﻿// /*
//  * @Author: wanyiming
//  * @Date:2024-07-15-20:17
//  * @Description:
//  */

using UnityEngine;

namespace Code.GameLogic.XianJian.XianJianBehavior.CommonBehavior
{
    public static class LockTargetBehavior
    {
        private static readonly float Offset=45f;
        
        public static void LockAtTigerBox(GameObject thisObj,GameObject tiger,float rotationSpeed)
        {
            if(tiger is null||thisObj is null) return ;
            Vector3 direction = tiger.transform.position - thisObj.transform.position;
            direction.z = 1f; // 将Z轴设置为，保持在XY平面上
            // 计算旋转角度
            float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
            // 进行旋转
            Quaternion targetRotation = Quaternion.Euler(0, 0, angle+Offset);
            thisObj.transform.rotation = Quaternion.Lerp(thisObj.transform.rotation,
                targetRotation, rotationSpeed * Time.deltaTime);
        }
        
        
    }
}